# build user login page with nicegui

from nicegui import ui, app

from ServerSide.Logic.Login import LoginLogic
from fastapi import Request




@ui.page('/registerform')
def registerform(request: Request):
    ip=(request.client.host)
    ui.label("注册")
    loginc = LoginLogic()

    # nicegui input
    input1=ui.input(label='手机', placeholder='start typing',
             validation={'Input too long': lambda value: len(value) < 12})
    input2=ui.input(label='密码', placeholder='start typing',password=True,
             validation={'Input too long': lambda value: len(value) < 13 and len(value) >7})
    input3 = ui.input(label='确认密码', placeholder='start typing',password=True,
                      validation={'Input too long': lambda value: len(value) < 13 and len(value) > 7},
                      on_change=lambda e:loginc.checkPassword(input2.value,input3.value,v))
    v=ui.label("")

    ui.button('注册', on_click=lambda:loginc.register(input1.value, input2.value,ip))